
// import { Buffer } from 'buffer'
// import crypto from 'crypto'



const key = "82c22b07c5654dcf82c22b07c5654dcf";
const iv = "qwerty1234rfidjs";

const aesObj = {
    16: "aes-128-gcm",
    24: "aes-192-gcm",
    32: "aes-256-gcm",
};

// const AES_KEY = CryptoJS.enc.Utf8.parse(key);
// const AES_IV = CryptoJS.enc.Utf8.parse(iv);

function entryCode(word) {
    try {
        var pwd = Buffer.from(key, 'hex');
        var iv = crypto.randomBytes(12);
        var cipher = crypto.createCipheriv('aes-128-gcm', pwd, iv);
        var enc = cipher.update(word, 'utf8', 'hex');
        enc += cipher.final('hex');
        var tags = cipher.getAuthTag();
        enc = Buffer.from(enc, 'hex');
        // 由于和java对应的AES/GCM/PKCS5Padding模式对应 所以采用这个拼接
        var totalLength = iv.length + enc.length + tags.length;
        var bufferMsg = Buffer.concat([iv, enc, tags], totalLength);
        return bufferMsg.toString('hex');
      } catch (e) {
        console.log("Encrypt is error", e);
        return null;
      }
}

function decryptCode(word) {
    // const BigInteger = forge.jsbn.BigInteger;
    // const n = forge.util.createBuffer(modules).toString("hex");
    // const e = forge.util.createBuffer(publicExponent).toString("hex");
    // const d = forge.util.createBuffer(privateExponent).toString("hex");
    // const privateKey = forge.pki.setRsaPrivateKey(new BigInteger(n, 16), new BigInteger(e, 16), new BigInteger(d, 16));

    // const res = privateKey.decrypt(res, "RSA-OAEP", {
    //     md: forge.md.sha256.create(),
    //     mgf1: {
    //         md: forge.md.sha256.create(),
    //     },
    // });
    // return res;
}
